{% from "../../macros/attributes.njk" import govukAttributes -%}

<div class="govuk-error-summary
  {%- if params.classes %} {{ params.classes }}{% endif %}"
  {%- if params.disableAutoFocus !== undefined %} data-disable-auto-focus="{{ params.disableAutoFocus }}"{% endif %}
  {{- govukAttributes(params.attributes) }} data-module="govuk-error-summary">
  {#- Keep the role="alert" in a seperate child container to prevent a race condition between
  the focusing js at the alert, resulting in information getting missed in screen reader announcements #}
  <div role="alert">
    <h2 class="govuk-error-summary__title">
      {{ params.titleHtml | safe | trim | indent(6) if params.titleHtml else params.titleText }}
    </h2>
    <div class="govuk-error-summary__body">
      {% if caller or params.descriptionHtml or params.descriptionText %}
      <p>
        {{ caller() if caller else (params.descriptionHtml | safe | trim | indent(8) if params.descriptionHtml else params.descriptionText) }}
      </p>
      {% endif %}
      {% if params.errorList | length %}
        <ul class="govuk-list govuk-error-summary__list">
        {% for item in params.errorList %}
          <li>
          {% if item.href %}
            <a href="{{ item.href }}"
              {{- govukAttributes(item.attributes) }}>
              {{- item.html | safe | trim | indent(12) if item.html else item.text -}}
            </a>
          {% else %}
            {{ item.html | safe | trim | indent(10) if item.html else item.text }}
          {% endif %}
          </li>
        {% endfor %}
        </ul>
      {% endif %}
    </div>
  </div>
</div>
